(function($){
    var client = new com.im.common.ajax();
    var loading = false;

    var methods = {
        init: function(options) {
            var o = $.extend({
                elmIdModal : "userSearchModal",//需要展示的位置
                elmIdOut : "userOut",//单击时回填的文本框
                callbackFunc: function(staffId,staffName) {
                }
            }, options || {});

            var self = this;

            onInit(o);

            return this;
        },
        treeOnClickInner : function(self,opt){
            //加载数据
            return o.treeOnClick('1','test');
        }

    };

    function onInit(opt) {
        //渲染查询界面
        _render(opt);


    };



    function _render(opt){
        //获取模态框
        var modal = $("#"+opt.elmIdModal);
        //清空
        modal.empty();
        var pDiv = $($.parseHTML(''));
        modal.append(pDiv);
        $("#"+opt.elmIdModal).modal("show");

    };
    function _queryOrgList(pageNum){

        $("#comp_org_list_tab").empty();
        var pageInfo = {};
        pageInfo.pageNumber = pageNum;
        pageInfo.pageSize  = 15
        orgparam.pageInfo  = pageInfo;

        var result = client.callAsJson("userService/queryOrgarizationsByCond", orgparam);
        if (result.success) {
            if(result.result != null){
                $("#comp_org_list_tab").datagrid({
                    columns : orgcolumns,
                    data : result.result
                });
                //TODO 显示分页
            }
        } else {
            toastr.error("服务器忙！请稍后再试！"+result.resultMsg);
        }

    };

    function _returnFunc(opt){
        var orgIdx = $("input[name='r1']:checked").val();
        if(orgIdx != undefined){
            var org = $('#comp_org_list_tab').datagrid('getData').rows[orgIdx];
            if(opt.elmIdOut != null && opt.elmIdOut != undefined){
                $("#"+opt.elmIdOut).val(org.orgName);
                $("#"+opt.elmIdOut).attr("orgId",org.orgId);
            }
            $("#"+opt.elmIdModal).modal("hide");
            return opt.callbackFunc(org.orgId,org.orgName);
        }else{
            toastr.warning("您未选择任何组织单位!!");
        }
    };
    
    $.fn.userSearchCommpent = function(method) {

        if (methods[method] && method.charAt(0) != '_') {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method ' +  method + ' does not exist on jQuery.pagination');
        }
    };

})(jQuery);